#include <bits/stdc++.h>
using namespace std;
class TreeNode
{
    public:
 int val;
 TreeNode *left;
 TreeNode *right;
 TreeNode():val(0),left(nullptr),right(nullptr){}
 TreeNode(int i):val(i),left(nullptr),right(nullptr){}
 TreeNode(int i,TreeNode*l,TreeNode*r):val(i),left(l),right(r){}
};
class interger
{
    private:
    int data;
    public:
    interger(int i=0)
    {
        this->data=i;
    }
    interger operator++(int)//后缀加法
    {
        interger tmp(this->data);
        this->data=1+this->data;
        return tmp;
    }
    interger operator++()//前缀加法
    {
        //  interger tmp(1+this->data);
        //  return tmp;
        this->data=1+this->data;
        return *this;
    }
    interger operator--(int)
    {
        interger tmp(this->data);
        this->data=(this->data)-1;
        return tmp;
    }
    interger operator--()
    {
        this->data=(this->data)-1;
        return *this;
    }
    friend ostream& operator<<(ostream& os,const interger& dt)
    {
        os<<dt.data;
        return os;
    }
};
vector<int>res;
void midfun(TreeNode*root)
{
    if(!root)return;
    if(root->left)
    midfun(root->left);
    res.push_back(root->val);
    if(root->right)
    midfun(root->right);
}
void midfun2(TreeNode*root)
{
    stack<TreeNode*>s;
    TreeNode*p=root;
    while(p!=nullptr||!s.empty())
    {
        while(p)
        {
            s.push(p);
            p=p->left;
        }
        if(!s.empty())
        {
            p=s.top();
            s.pop();
            res.push_back(p->val);
            p=p->right;
        }
    }
}
void prefun(TreeNode*root)
{
    if(!root)return;
    res.push_back(root->val);
    if(root->left)
    prefun(root->left);
    if(root->right)
    prefun(root->right);
}
void prefun2(TreeNode*root)
{
    stack<TreeNode*>s;
    TreeNode *p=root;
    while(p||!s.empty())
    {
        while(p)
        {  s.push(p);
           res.push_back(p->val);
            p=p->left;
        }
        if(!s.empty())
        {
            p=s.top();
            s.pop();
            p=p->right;
        }
    }
}
void postfun(TreeNode*root)
{
    if(!root)return;
    postfun(root->left);
    postfun(root->right);
    res.push_back(root->val);
}
void postfun2(TreeNode*root)
{
    stack<TreeNode*>s;
    TreeNode*p=root;
    TreeNode *pre=nullptr;
    while(p!=nullptr||!s.empty())
    {
        while(p)
        {
            s.push(p);
            p=p->left;
        }
        if(!s.empty())
        {
            p=s.top();
            s.pop();
            if(p->right==nullptr||pre==p->right)
            {
                res.push_back(p->val);
                pre=p;
                p=nullptr;
            }
            else
            {
                s.push(p);
                p=p->right;
            }
        }
    }
}
int main()
{
interger a(3),b(5);
cout<<a<<" "<<b<<"\n";
cout<<a++<<" "<<++b<<"\n";
cout<<a<<" "<<b<<"\n";
TreeNode *root=new TreeNode(4);
TreeNode *p1=new TreeNode(2);
TreeNode *p2=new TreeNode(1);
TreeNode *p3=new TreeNode(3);
TreeNode *p4=new TreeNode(6);
root->left=p1;
root->right=p4;
p1->left=p2;
p1->right=p3;
postfun2(root);
for(auto x:res)
{
    cout<<x<<" ";
}
cout<<"\n";
delete root,p1,p3,p4;


 
}
